package com.cc.config;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;

import javax.servlet.Filter;

/**
 * @author 33314
 * @version 1.0
 * @description: TODO创建WebConfig类继承AbstractDispatcherServletInitializer类
 * @date 2025/6/9 19:25
 *
 */

public class WebConfig extends AbstractDispatcherServletInitializer {
    /** 
     * @description:  
     * @param: 创建springMVC容器
     * @return: org.springframework.web.context.WebApplicationContext 
     * @author 33314
     * @date: 2025/6/9 19:26
     */ 
    @Override
    protected WebApplicationContext createServletApplicationContext() {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.register(SpringMVCConfig.class);
        return context;
    }
/**
 * @description:
 * @param: 创建web容器映射路径
 * @return: java.lang.String[]
 * @author 33314
 * @date: 2025/6/9 19:26
 */
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
/**
 * @description:
 * @param: 创建spring容器
 * @return: org.springframework.web.context.WebApplicationContext
 * @author 33314
 * @date: 2025/6/9 19:26
 */
    @Override
    protected WebApplicationContext createRootApplicationContext() {
        return null;
    }
//    创建过滤器 解决中文乱码
    @Override
    protected Filter[] getServletFilters() {
        return new Filter[]{new CharacterEncodingFilter("UTF-8",true)};
    }
}
